package cn.sm1234.service.impl;

import cn.sm1234.service.CustomerService;
//import com.clf.mapper.CustomerMapper;
//import com.clf.model.Customer;
//import com.clf.model.CustomerExample;


import com.example.mapper.CustomerMapper;
import com.example.pojo.Customer;
import com.example.pojo.CustomerExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author http://www.sm1234.cn
 * @version 1.0
 * @description cn.sm1234.service.impl
 * @date 18/4/1
 */
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public void save(Customer customer) {
        customerMapper.insert(customer);
    }

    @Override
    public Customer mySelectByID(String id) {

        return customerMapper.mySelectByID(id);

    }

    @Override
    public Customer mySelectByIDAndName(String id, String name) {

        return customerMapper.mySelectByIDAndName(id, name);

    }


    public Customer mySelectByPojo(Customer customer) {

        return customerMapper.mySelectByPojo(customer);
    }

    public Customer mySelectByPojo2(Customer customer) {

        return customerMapper.mySelectByPojo2(customer);
    }



    @Override
    public List<Customer> selectByID(String id) {
        CustomerExample customerExample = new CustomerExample();
        customerExample.createCriteria().andIdEqualTo(Integer.parseInt(id));

        System.out.println("service层CustomerServiceImpl类中selectByID方法执行中");

        List<Customer> customers = customerMapper.selectByExample(customerExample);
        return customers;
    }

    public Integer myInsert(Customer customer) {
        return customerMapper.myInsert(customer);
    }

    @Override
    public Customer queryByExample(Customer customer) {
        System.out.println("service层CustomerServiceImpl类中queryByExample方法执行中");
        CustomerExample customerExample = new CustomerExample();

        CustomerExample.Criteria criteria1 = customerExample.createCriteria();
        criteria1.andIdEqualTo(3);

        criteria1.andGenderEqualTo("male");

        CustomerExample.Criteria criteria2 = customerExample.or();
        criteria2.andAgeGreaterThan(18);


        List<Customer> customers = customerMapper.selectByExample(customerExample);
        if (customers.size() > 0) {
            return customers.get(0);
        } else {
            Customer customer1 = new Customer();
            customer1.setName("未找到该用户");
            return customer1;
        }
    }


    @Override
    public Customer queryByCondition(Customer customer) {
        System.out.println("service层CustomerServiceImpl类中queryByCondition方法执行中");

        List<Customer> customers = customerMapper.selectByComplexCondition(customer);


        if (customers.size() > 0) {
            return customers.get(0);
        } else {
            Customer customer1 = new Customer();
            customer1.setName("未找到该用户");
            return customer1;
        }
    }

    @Override
    public Customer queryByName(String name) {
        System.out.println("service层CustomerServiceImpl类中queryByName方法执行中");

       List<Customer>  customer = customerMapper.queryByName(name);

       if (customer.size() > 0) {
            return customer.get(0);
        }else {
            Customer customer1 = new Customer();
            customer1.setName("未找到该用户");
            return customer1;
        }
    }
}
